/*
 * Copyright (c) 2023 Huawei Technologies Co., Ltd.
 * openUBMC is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *         http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */

#ifndef PCIE_DEVICE_INTERFACE_H
#define PCIE_DEVICE_INTERFACE_H

#include <mc/core/timer.h>
#include <mc/engine/service.h>

#include <device_tree/interface/PCIeDevice.h>
#include <ncsi_over_mctp/ncsi_over_mctp_huawei.h>

namespace dev {

using ncsi_over_mctp_hw_ptr = std::shared_ptr<ncsi_over_mctp_huawei>;

class PCIeDevice : public mc::engine::interface<PCIeDevice, gen::PCIeDevice> {
public:
    PCIeDevice()  = default;
    ~PCIeDevice() = default;

public:
    // 设备数接口实现
    bool SetRootBDF(uint8_t bus, uint8_t device, uint8_t function) override;
    bool SetDeviceBDF(uint8_t bus, uint8_t device, uint8_t function) override;

public:
    // ncsi over mctp 华为自定义命令实现
    bool update_pcie_device_id_by_ncsi();
    void start_ncsi_update_task_huawei(ncsi_over_mctp_hw_ptr ncsi_over_mctp,
                                       mc::milliseconds      interval);
    void stop_ncsi_update_task();

private:
    ncsi_over_mctp_hw_ptr m_ncsi_over_mctp_huawei;
    mc::core::timer*      m_ncsi_timer;

public:
    void replace_dynamic_property(mc::mutable_dict& object, const mc::dict& connector);
    mc::signal<void(uint8_t, uint8_t, uint8_t)> pcie_device_bdf_changed;
};

} // namespace dev

#endif // PCIE_DEVICE_INTERFACE_H